import { Inject } from '@midwayjs/core';
import { CoolController, BaseController } from '@cool-midway/core';
import { CustomerAssignEntity } from '../../entity/assign';
import { CustomerAssignService } from '../../service/assign';
import { BaseSysUserEntity } from '../../../base/entity/sys/user';

/**
 * 客户分配
 */
@CoolController({
  api: ['add', 'delete', 'update', 'info', 'list', 'page'],
  entity: CustomerAssignEntity,
  service: CustomerAssignService,
  pageQueryOp: {
    fieldEq: ['a.reason'],
    join: [
      {
        entity: BaseSysUserEntity,
        alias: 'b',
        condition: 'a.oldUserId = b.id',
        type: 'leftJoin',
      },
      {
        entity: BaseSysUserEntity,
        alias: 'c',
        condition: 'a.newUserId = c.id',
        type: 'leftJoin',
      },
    ],
    select: ['a.*', 'b.nickName as oldUserName', 'c.nickName as newUserName'],
  },
})
export class AdminCustomerAssignController extends BaseController {
  @Inject()
  customerAssignService: CustomerAssignService;
}
